﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace RestaurantManager.DataAcess
{
    class ConnectData
    {
        SqlConnection conn;
        SqlDataAdapter adap;
        DataTable dtb = new DataTable();
        public ConnectData()
        {
            ConData();
        }
        public void ConData()
        {
            string strConn = @"Data Source=VHC-AD8731EB5F7\SQLEXPRESS;Initial Catalog=RestaurantManager;Integrated Security=True";
            try
            {
                conn = new SqlConnection(strConn);
                conn.Open();
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi", ex.Message);
            }

        }
        public DataTable ExecuteDataTable(string sql)
        {
            adap = new SqlDataAdapter(sql, conn);
            adap.Fill(dtb);
            return dtb;
        }
        public bool ExecuteQuery(string sql)
        {
            int numberecords = 0;
            try
            {
                SqlCommand com = new SqlCommand(sql);
                com.Connection = conn;
                conn.Open();
                numberecords = com.ExecuteNonQuery();
                conn.Close();
                
            }
            catch (Exception ex)
            {

                MessageBox.Show("Loi", ex.Message);
                
            }
            if (numberecords > 0)
                return true;
            return false;
        }
    }
}

